package com.cms.common.service;

import java.util.Locale;
import java.util.Map;

import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;

/**
 * 自定义多视图解析器
 * @author lifer
 *
 */
public class MultiViewResover implements ViewResolver {

	private Map<String, ViewResolver> resolvers;

	@Override
	public View resolveViewName(String viewName, Locale locale)
			throws Exception {
		ViewResolver resolver = resolvers.get("ftl");
		int n = viewName.lastIndexOf("."); // 获取
		if (n == (-1))return resolver.resolveViewName(viewName, locale);
		String suffix = viewName.substring(n + 1);
		resolver = resolvers.get(suffix);
		viewName = viewName.substring(0, n);
		if (resolver != null)return resolver.resolveViewName(viewName, locale);
		return null;
	}

	public Map<String, ViewResolver> getResolvers() {
		return resolvers;
	}

	public void setResolvers(Map<String, ViewResolver> resolvers) {
		this.resolvers = resolvers;
	}

}
